//
//  PMJoint.m
//  PezMonkey
//
//  Created by Spence DiNicolantonio on 10/30/09.
//  Copyright 2009 Necrosoft. All rights reserved.
//

/**
 * A rigid body joint. PMJoints are used to connect two PMBodys.
 * This class should never be instantiated directly, rather, PMJoints should be 
 * instantiated using the PMPinJoint, PMSlideJoint, PMPivotJoint, and PMGrooveJoint 
 * subclasses.
 * 
 * PMPinJoint
 * Connects two PMBodys with a solid pin or rod. The ends of the "rod" are anchored 
 * to each body, keeping the two anchor points a set distance from each other.
 * 
 * PMSlideJoint
 * Like PMPinJoints, but have flexible anchors. A Minimum and maximum limit is 
 * used to constrain the anchors freedom.
 *
 * PMPivotJoint
 * Ties two PMBodys together at a single pivot point.
 *
 * PMGrooveJoint
 * Like a PMPinJoint with one flexible anchor. A joint with a pin anchor on one
 * body and a slide anchor on the other.
 */
 
#import "PMJoint.h"


@implementation PMJoint

@synthesize bodyA;
@synthesize bodyB;


#pragma mark -
#pragma mark Dealloc

/**
 * Releases member objects and frees memory used for cpJoint before deallocating.
 */
- (void)dealloc {
	[self.bodyA release];
	[self.bodyB release];
	cpJointFree(joint);
	[super dealloc];
}


#pragma mark -
#pragma mark Getters

/**
 * Returns the receiver's cpJoint reference. This is not intended for external use.
 */
- (cpJoint *)cpJoint {
	return joint;
}

/**
 * Returns the receiver's joint type.
 */
- (PMJointType)type {
	return (PMJointType) joint->klass->type;
}

/**
 * Returns the receiver's referenced rigid body corresponding to the given key.
 */
- (PMBody *)bodyForKey:(PMJointBodyKey)bodyKey {
	switch (bodyKey) {
		case PMJointBodyKeyA:
			return self.bodyA;
		case PMJointBodyKeyB:
			return self.bodyB;
		default:
			return nil;
	}
}

@end
